package com.yyysj.system.controller;

import com.yyysj.common.core.domain.Result;
import com.yyysj.common.core.domain.TableDataInfo;
import com.yyysj.system.domain.dto.ExamAddDTO;
import com.yyysj.system.domain.dto.ExamEditDTO;
import com.yyysj.system.domain.dto.ExamQueryDTO;
import com.yyysj.system.domain.dto.ExamQuestionAddDTO;
import com.yyysj.system.domain.vo.ExamDetailVO;
import com.yyysj.system.service.IExamService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/exam")
@Tag(name = "竞赛管理接口")
@RequiredArgsConstructor
public class ExamController {

    private final IExamService examService;

    @GetMapping("/list")
    public TableDataInfo list(ExamQueryDTO examQueryDTO) {
        return examService.list(examQueryDTO);
    }

    @PostMapping("/add")
    public Result<String> add(@RequestBody ExamAddDTO examAddDTO) {
        return examService.add(examAddDTO);
    }

    @PostMapping("/question/add")
    public Result<?> questionAdd(@RequestBody ExamQuestionAddDTO examQuestionAddDTO) {
        return examService.questionAdd(examQuestionAddDTO);
    }

    @GetMapping("/detail")
    public Result<ExamDetailVO> detail(Long examId) {
        return Result.ok(examService.detail(examId));
    }

    @PutMapping("/edit")
    public Result<Void> edit(@RequestBody ExamEditDTO examEditDTO) {
        int rows = examService.edit(examEditDTO);
        if (rows > 0) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }

    @DeleteMapping("/question/delete")
    public Result<?> questionDelete(Long examId, Long questionId) {
        int rows = examService.questionDelete(examId, questionId);
        if (rows > 0) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }

    @DeleteMapping("/delete")
    public Result<?> delete(Long examId) {

        int rows = examService.delete(examId);
        if (rows > 0) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }

    @PutMapping("/publish")
    public Result<?> publish(Long examId) {
        return Result.build(examService.publish(examId));
    }

    @PutMapping("/cancelPublish")
    public Result<?> cancelPublish(Long examId) {
        return Result.build(examService.cancelPublish(examId));
    }
}
